//
//  VistorTableController.swift
//  WeiboSwift
//
//  Created by Apple13 on 16/7/9.
//  Copyright © 2016年 yupeng. All rights reserved.
//

import UIKit

class VistorTableController: UITableViewController {
    
    //登录标识
    var isLogin:Bool = UserAccountViewModel.shareUserAccount.isLogin
    
    
    //访客视图
    var vistorView: VistorView?
    
    override func loadView() {
        if isLogin{
            super.loadView()
        }else{//未登录 - 加载访客视图
            vistorView = VistorView()
             view = vistorView
//‼️  设置闭包
            vistorView?.loginClosure = { [weak self] in
//                print(self)
//                print("点击了中间的")
                self?.showOAuthLogin()
                
            }
            
           
            
            setUpNaviUI()
        }
    }
    

    //MARK: - 设置导航栏
    private func setUpNaviUI() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginAction")
        
    }
    
    
//MARK: - 设置点击事件
    @objc private func registerAction(){
        print("点击了注册")
        showOAuthLogin()
    
    }
    
    @objc private func loginAction() {
        print("点击了登录")
        showOAuthLogin()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

    
    //MARK: - OAuth登录页面
    private func showOAuthLogin(){
        let oAuthVC = OAuthViewController()
        let nav = UINavigationController(rootViewController:oAuthVC)
        
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
    
    
    
    
    
    
    
    
    
    
   
}
